package model;

import java.util.logging.Level;
import java.util.logging.Logger;

import model.interfaces.DicePair;
import model.interfaces.GameEngine;
import model.interfaces.GameEngineCallback;
import model.interfaces.Player;

/**
 * 
 * Skeleton example implementation of GameEngineCallback showing Java logging behaviour
 * 
 * @author Caspar Ryan
 * @see model.interfaces.GameEngineCallback
 * 
 */
public class GameEngineCallbackImpl implements GameEngineCallback
{
	private Logger logger = Logger.getLogger("assignment1");

	public Logger getLogger() {
		return logger;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public GameEngineCallbackImpl()
	{
		// FINE shows rolling output, INFO only shows result
		logger.setLevel(Level.FINE);
		Logger.getGlobal().getParent().getHandlers()[0].setLevel(Level.FINE);//To generate a new handlers, cause some issues cannot shown

	}

	@Override
	public void intermediateResult(Player player, DicePair dicePair, GameEngine gameEngine)
	{
		// intermediate results logged at Level.FINE
		logger.log(Level.FINE, String.format("%s: ROLLING "+dicePair.toString(),player.getPlayerName()));//Logging format
		// TO DO: complete this method to log results
	}

	@Override
	public void result(Player player, DicePair result, GameEngine gameEngine)
	{
		// final results logged at Level.INFO
		logger.log(Level.INFO, String.format("%s: *RESULT* "+result.toString(),player.getPlayerName()));//Logging format
		// TO DO: complete this method to log results
	}

	@Override
	public void intermediateHouseResult(DicePair dicePair, GameEngine gameEngine) {//wait editing
		logger.log(Level.FINE, String.format("HOUSE: ROLLING "+dicePair.toString()));//Logging format
	}

	@Override
	public void houseResult(DicePair result, GameEngine gameEngine) {//wait editing
		logger.log(Level.INFO, String.format("HOUSE: *RESULT* "+result.toString()));//Logging format
	}

	public void playerResult(Player player, GameEngine gameEngine)//get player result format out put
	{
		logger.log(Level.INFO, String.format("Player: id:%s, Name:%s, Points: %d ", player.getPlayerId(),player.getPlayerName(),player.getPoints()));//Logging format
	}
	// TO DO: complete the GameEngineCallback interface implementation

}
